import request from '@/utils/request'
import { ARTICLE_CHANNELS_GET, ARTICLE_LIST } from '../constants'

export const articleChannelsGetAc = (payload) => ({
  type: ARTICLE_CHANNELS_GET,
  payload,
})
/**
 * 获取频道数据
 */
export const articleChannelsGet = () => {
  return async (dispatch) => {
    const { data } = await request.get('/channels')
    dispatch(articleChannelsGetAc(data.data.channels))
  }
}

export const articleListAc = (payload) => ({
  type: ARTICLE_LIST,
  payload,
})
/**
 * 获取文章数据
 */
export const articleList = (params) => {
  return async (dispatch) => {
    const { data } = await request.get('/mp/articles', {
      params,
    })
    dispatch(articleListAc(data.data))
  }
}

/**
 * 删除文章
 */
export const articleDel = (id) => {
  return async () => {
    await request.delete(`mp/articles/${id}`)
  }
}
